package com.koudai.reader.vo;

import android.content.Context;
import android.content.SharedPreferences;

import com.koudai.reader.util.Constant;


public class ReadBookConfig {

    private static ReadBookConfig instance = new ReadBookConfig();
    private  Context context;
    
    private int fontSize = Constant.config_font_size_3;
    private int lineSpace = Constant.config_space_size_mid;
    private int bg = Constant.config_bg_type_default;
    
    private ReadBookConfig(){
        
    }
    
    public void init(Context context) {
        this.context = context;
        
        SharedPreferences config = context.getSharedPreferences("config", 0);
        fontSize = config.getInt(Constant.config_font_size, Constant.config_font_size_3);
        
        lineSpace = config.getInt(Constant.config_space_size, Constant.config_space_size_mid);
        
        bg = config.getInt(Constant.config_bg_type, Constant.config_bg_type_default);
    }
    
    public static ReadBookConfig getInstance(){
        
        return instance;
    }

    /**
     * @return the fontSize
     */
    public int getFontSize() {
        return fontSize;
    }

    /**
     * @param fontSize the fontSize to set
     */
    public void setFontSize(int fontSize) {
        
        SharedPreferences config = context.getSharedPreferences("config", 0);
        config.edit().putInt(Constant.config_font_size, fontSize).commit();
        
        this.fontSize = fontSize;
    }

    /**
     * @return the lineSpace
     */
    public int getLineSpace() {
        return lineSpace;
    }

    /**
     * @param lineSpace the lineSpace to set
     */
    public void setLineSpace(int lineSpace) {
        SharedPreferences config = context.getSharedPreferences("config", 0);
        config.edit().putInt(Constant.config_space_size, lineSpace).commit();
        this.lineSpace = lineSpace;
    }

    /**
     * @return the bg
     */
    public int getBg() {
        return bg;
    }

    /**
     * @param bg the bg to set
     */
    public void setBg(int bg) {
        SharedPreferences config = context.getSharedPreferences("config", 0);
        config.edit().putInt(Constant.config_bg_type, bg).commit();
        this.bg = bg;
    }
    
}
